package com.cdc.videodemo;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.util.Log;

public class ILog {
	
    public static <T>  void i(T tag,T message){
    	if(tag instanceof String){
    		Log.i((String)tag,message+"");
    	}else{
    		String tagHashCode=tag.toString();
    		Log.i(getTagClass(tagHashCode),getTagSubClass(tagHashCode)+message);
    	}
    }

    


    /**获取类名
     * <p>包名.类名@hashCode</p>
     * <p>包名.类名$子类名@hashCode</p>
     * */
    private static String getTagClass(String str){
    	String temp=null;
    	if(str.contains("$")){
    		//截取.和$之间的字符串,且不包含.和$.
    		Pattern p = Pattern.compile("[^\\.]+(?=\\$)");
    		Matcher m = p.matcher(str);
    		while(m.find()){
    			temp=m.group();
    		}
    	}else{
    		//截取.和@之间的字符串,且不包含.和$.
    		Pattern p = Pattern.compile("[^\\.]+(?=@)");
    		Matcher m = p.matcher(str);
    		while(m.find()){
    			temp=m.group();
    		}
    	}
    	return  temp;
    }
    
    private static String getTagSubClass(String str){
    	String temp=null;
    	if(str.contains("$")){
    		//截取$和@之间的字符串,且不包含$和@.
    		Pattern p = Pattern.compile("[^\\$]+(?=@)");
    		Matcher m = p.matcher(str);
    		while(m.find()){
    			temp=m.group()+",";
    		}
    	}else{
    		temp="";
    	}
    	return  temp;
    }

}
